<template>
  <el-dialog
    v-model="dialogVisible"
    :destroy-on-close="true"
    :align-center="true"
    width="50%"
    title="售后详情"
    style="padding: 20px"
  >
    <el-form
      ref="billFormRef"
      :rules="rules"
      :model="dialogData.itemInfo"
      label-width="120px"
      label-suffix=" :"
    >
          <el-form-item label="标题">
            <el-input readonly v-model="dialogData.itemInfo.title" placeholder="标题"></el-input>
          </el-form-item>
          <el-form-item label="售后内容">
            <el-input readonly :rows="4" type="textarea" v-model="dialogData.itemInfo.content" placeholder="售后内容"></el-input>
          </el-form-item>
          <el-form-item label="售后凭证">
            <section class="file-upload-box">
                <UploadImgs
                  v-model:fileList="dialogData.fileList"
                  :file-size="3"
                  :disabled="true"
                  width="160px"
                  height="160px"
                >
                  <template #tip> 不超过 3M </template>
                </UploadImgs>
              </section>
          </el-form-item>
          <el-divider />
          <el-form-item label="处理结果">
            <el-input readonly :rows="4" type="textarea" v-model="dialogData.itemInfo.dealContent" placeholder="处理结果"></el-input>
          </el-form-item>
          <el-form-item label="处理时间">
            <el-input disabled v-model="dialogData.itemInfo.dealDate" placeholder="处理时间"></el-input>
          </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false">关闭</el-button>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
import { ref, reactive } from "vue";
import { getOptTitle, OptEnum } from "@/biz/eenum/appEnum";
import { DialogParam } from "@/biz/interface/DialogType";
import { getAbnormalInfoApi } from "@/api/modules/cpyjob/abnormal"; 
import { AbnormalEntity } from "@/biz/interface/modules/AbnormalType";
import UploadImgs from "@/components/Upload/ImgMultiple.vue";

//页面的数据
interface flexjobAbnormalDialogOption extends DialogParam {
  //弹出表单的标题
  title: string;
  // 图片
  fileList: [];
  //当前的数据对象
  itemInfo: AbnormalEntity;
  //其它的数据都继续在这里加
}
//提交按钮，避免多次提交
// const btnLoading = ref(false);
//弹出框的参数
const dialogVisible = ref(false);
//当前表单数据在这里初始化
const dialogData = reactive<flexjobAbnormalDialogOption>({
  optType: OptEnum.UNKNOW,
  title: "",
  fileList: [],
  itemInfo: {}
});

// 接收父组件传过来的参数
const acceptParams = (params: DialogParam): void => {
  dialogData.optType = params.optType;
  dialogData.rowData = params.rowData;
  dialogData.title = getOptTitle(dialogData.optType);

  if (dialogData.rowData) {
    initItemInfo();
    getItemInfo(dialogData.rowData.id);
  }

  dialogVisible.value = true;
};

//初始化页面的数据
const initItemInfo = (): void => {
  dialogData.itemInfo = { };
};

//获取当前数据的详情，直接调用接口获取数据
const getItemInfo = async (id: string) => {
  if (id) {
    let { data } = await getAbnormalInfoApi({ jobId:id });
    dialogData.itemInfo = data as unknown as AbnormalEntity;
    // 处理图片和视频
    dialogData.fileList.length = 0;
    let imgIdx = 1;
    if (dialogData.itemInfo.reses) {
      dialogData.itemInfo.reses.forEach(item => {
        dialogData.fileList.push({ name: imgIdx, url: item.resUrl });
        imgIdx = imgIdx + 1;
      });
    }
  }
};

//数据较验
const rules = reactive({
  billNo: [{ required: true, message: "请填写公司税号", trigger: "blur" }]
});

//页面参数
defineExpose({
  acceptParams
});
</script>
<style scoped lang="scss"></style>
